<template>
  <div class="login_container">
    <!-- 登录框 -->
    <div class="login_box">
      <!-- logo -->
      <img src="../assets/logo1.jpg" alt="" class="login_img" />
      <el-form
        ref="loginFormRef"
        :model="userForm"
        label-width="0px"
        class="login_form"
        :rules="userRules"
      >
        <!-- 登陆表单区域 -->
        <el-form-item prop="username">
          <el-input
            v-model="userForm.username"
            placeholder="请输入注册用户名"
            prefix-icon="el-icon-user"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="userForm.password"
            prefix-icon="el-icon-lock"
            placeholder="请输入密码"
            show-password
          ></el-input>
        </el-form-item>
      </el-form>
      <el-button type="primary" @click="register">注册</el-button>
      <el-button type="info" @click="back">返回</el-button>
    </div>
    <div class="videoContainer">
      <video
        class="fullscreenVideo"
        id="bgVid"
        playsinline=""
        autoplay=""
        muted=""
        loop=""
      >
        <source src="../assets/2.mp4" type="video/mp4" />
      </video>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userForm: {
        username: "",
        password: "",
        checkpass: "",
      },
      userRules: {
        username: [
          { required: true, message: "用户名不能为空", trigger: "blur" },
          {
            min: 3,
            max: 15,
            message: "用户名长度在3到15个字符",
            trigger: "blur",
          },
        ],
        password: [
          {
            required: true,
            message: "密码不能为空",
            trigger: "blur",
          },
          {
            min: 6,
            max: 15,
            message: "密码长度在 6 到 15 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    register() {
      this.$refs.loginFormRef.validate(async (valid) => {
        // 如果valid参数为true则未验证通过
        if (!valid) return;
        const { data: res } = await this.$http.post("registry", this.userForm);
        // 判断
        if (res.code != 200) return this.$message.error(res.msg);
        this.$message.success(res.msg);
        // 跳转
        this.$router.push("/login");
      });
    },
    back() {
      this.$router.push("/login");
    },
  },
};
</script>

<style lang="less" scoped>
// .login_container {
//   background-color: rgb(98, 232, 185);
//   background-image: url(../assets/4.jpg);
//   width: 100%;
//   height: 100%;
//   background-size: cover;
// }
.login_box {
  height: 300px;
  width: 460px;
  //background-color: rgba(220, 230, 220, 0.5);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 10px;
  opacity: 0.8;
}
.login_img {
  height: 90px;
  margin-left: 104px;
  margin-top: 30px;
  width: 300px;
}
.login_form {
  margin-left: 100px;
  margin-right: 80px;
  width: 308px;
}
.el-button {
  margin-left: 260px;
}

.videoContainer {
  position: fixed;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: -100;
}

.videoContainer:before {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  display: block;
  z-index: -1;
  top: 0;
  left: 0;
  background: rgba(25, 29, 34, 0.65);
  background-size: cover;
}

.fullscreenVideo {
  width: 100%;
  height: 100%;
  object-fit: fill;
}
</style>